package com.newcoder.controller;

import com.newcoder.entity.Message;
import com.newcoder.service.MessageService;
import com.newcoder.util.ResponseWrapper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjh
 * @since 2024-12-04 10:03:26
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @ApiOperation("查询当前用户所有对话框")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "userId"),
    })
    @GetMapping("/getLetterList")
    public ResponseWrapper getLetterList(@RequestParam(name = "userId")Integer userId){
        ResponseWrapper wrapper = messageService.getLetterList(userId);
        return wrapper;
    }

    @ApiOperation("查询详细对话框")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "userId"),
            @ApiImplicitParam(name = "conversationId",value = "conversationId"),
    })
    @GetMapping("/getLetterDetail")
    public ResponseWrapper getLetterDetail(@RequestParam(name = "userId")Integer userId, @RequestParam(name = "conversationId")String conversationId){
        ResponseWrapper wrapper = messageService.getLetterDetail(userId, conversationId);
        return wrapper;
    }

    @ApiOperation("发送消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "message",value = "信息实体"),
    })
    @PostMapping("/sendMessage")
    public ResponseWrapper sendMessage(@RequestBody Message message){
        ResponseWrapper wrapper = messageService.sendMessage(message);
        return wrapper;
    }

    @ApiOperation("查询某个主题下最新的通知")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "userId"),
            @ApiImplicitParam(name = "topic",value = "主题"),
    })
    @GetMapping("/getNoticeList")
    public ResponseWrapper getNoticeList(Integer userId, String topic){
        ResponseWrapper wrapper = messageService.getNoticeList(userId, topic);
        return wrapper;
    }

    @ApiOperation("询某个主题所包含的通知列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId",value = "userId"),
            @ApiImplicitParam(name = "topic",value = "主题"),
    })
    @GetMapping("/getNoticeDetail")
    public ResponseWrapper getNoticeDetail(Integer userId, String topic){
        ResponseWrapper wrapper = messageService.getNoticeDetail(userId, topic);
        return wrapper;
    }
}
